<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: del.class.php 17082 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
  defined('PHPFOX') or exit('NO DICE!');
  class Follow_Component_Controller_Del extends Phpfox_Component
  {
      public function process()
      {
          Phpfox::isUser(true);
          $sMessage = '';
          $iId = $this->request()->get('id', false);
          $sType = $this->request()->get('type', false);
          $iItemId = $this->request()->get('oid', false);
          if($sType == 'user')
            {
                $sLink = 'follow';
            }
            elseif($sType == 'pages')
            {
                $sLink = 'pages.'.$iItemId.'.follow.follower';
            }
            if(!empty($iId) && !empty($sType) && !empty($iItemId))
            {
              if(Phpfox::getUserId() == $iItemId && $sType == 'user')
              {
                    $sMessage = Phpfox::getPhrase('follow.you_can_not_unfollow_yourself');
              }
              if(Phpfox::getService('follow')->isUserExists($iId))
              {
                    if(Phpfox::getService('follow')->isFollow($iId, $iItemId, $sType))
                    {
                        if(Phpfox::getService('follow')->unFollow($iItemId, $iId, $sType))
                        {
                            $sMessage = Phpfox::getPhrase('follow.unfollow_successfully');
                        }
                        else
                        {
                            $sMessage = Phpfox::getPhrase('follow.unfollow_successfully');
                        }
                    }
                    else
                    {
                        $sMessage = Phpfox::getPhrase('follow.you_havent_followed_this_user_yet');
                    }
              }
              else
              {
                  $sMessage =  Phpfox::getPhrase('follow.user_id_not_exists');
              }
          }
          else
          {
              $sMessage = Phpfox::getPhrase('follow.missing_information_for_perform_this_action');
          }
          $this->url()->send($sLink,null,$sMessage);
      }
      
  }
?>
